package com.ly.repository;

import com.ly.entity.HouseSubscribe;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author ：LY
 * @date ：Created in 2020/11/26 20:45
 * @modified By：
 */
public interface HouseSubscribeRespository extends PagingAndSortingRepository<HouseSubscribe,Long> {

    HouseSubscribe findByHouseIdAndUserId(Long id,Long loginUserId);

    Page<HouseSubscribe> findAllByUserIdAndStatus(Long userId, int status, Pageable pageable);

    Page<HouseSubscribe> findAllByAdminIdAndStatus(Long adminId,int status, Pageable pageable);

    HouseSubscribe findByHouseIdAndAdminIdAndUserId(Long houseId, Long adminId,Long userId);

    @Modifying
    @Query("update HouseSubscribe as subsribe set subsribe.status = :status where subsribe.id=:id")
    void updateStatus(@Param(value = "id") Long id, @Param(value = "status")int value);
}
